package com.cloud2022.sharding.scheduled;

import com.cloud2022.sharding.mapper.DealerMapper;
import com.cloud2022.sharding.pojo.Dealer;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.awt.*;
import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author: create by God of SJF
 * @version: v1.0
 * @description: com.cloud2022.order.scheduled
 * @date:2022/2/7
 */
@Component
public class TestOss {

    static final int nThreads = Runtime.getRuntime().availableProcessors();

    public Integer poolSize = nThreads * 2;

    public ThreadPoolExecutor pool = new ThreadPoolExecutor(poolSize, poolSize,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());

    @Resource
    DealerMapper dealerMapper;

    @Scheduled(cron = "0/1 * * * * ? ")
    public void test(){
        int max=100,min=1;
        long randomNum = System.currentTimeMillis();
        int ran3 = (int) (randomNum%(max-min)+min);
        Dealer dealer = new Dealer();
        dealer.setName("haha"+ran3);
        dealerMapper.insertSelective(dealer);
    }


    public static void main(String[] args) {
        TestOss oss = new TestOss();
        System.out.println(oss.poolSize);

    }
}
